/**
 * desc: 获取当前系统时间
 * param: fmt - 格式化字符串
 * return: 暂无数据
 */
function getCurrentDate(fmt) {
	return timestampToFormatInfo(new Date().getTime(), fmt);
}

/**
 * desc: 格式化方法
 * param: timestamp - 时间戳
 * param: fmt - 格式化字符串
 * return: 暂无数据
 */
function timestampToFormatInfo(timestamp, fmt) {
	if (!timestamp) {
		return {
			timestamp: null,
			formatTime: null,
			date: null
		}
	}
	if (!fmt) {
		fmt = 'yyyy-MM-dd hh:mm:ss';
	}
	let cDate = new Date(timestamp);
	//北京时间比格林时间快8小时,+8以后时间戳将多出8小时
	cDate.setUTCHours(cDate.getUTCHours() + 8);
	let year = cDate.getUTCFullYear(),
		month = cDate.getUTCMonth() + 1, //月份
		day = cDate.getUTCDate(), //日
		hours = cDate.getUTCHours(), //小时
		minutes = cDate.getUTCMinutes(), //分
		seconds = cDate.getUTCSeconds(), //秒
		milliseconds = cDate.getUTCMilliseconds(), //毫秒
		quarter = Math.floor((month + 3) / 3) //季度

	let o = {
		"M+": month,
		"d+": day,
		"h+": hours,
		"m+": minutes,
		"s+": seconds,
		"q+": quarter,
		"S": milliseconds
	};

	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (year + "").substr(4 - RegExp.$1.length));
	}

	for (let k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (1 === RegExp.$1.length) ? (o[k]) : (("00" + o[k]).substr(("" + o[k])
			.length)));
		}
	}

	return {
		timestamp: timestamp,
		formatTime: fmt,
		date: cDate
	}
}

/**
 * desc: 根据字符串获取时间戳方法
 * param: timeStr - 字符串时间
 * return: 暂无数据
 */
function getTimestampByStr(timeStr) {
	//北京时间比格林时间快8小时,+8以后时间戳将多出8小时
	if (!timeStr) {
		return null;
	}

	let timezone = 8;
	let calDateTime = timezone * 60 * 60 * 1000;

	let date = new Date(timeStr);
	let dateTime;
	console.log(date.toString())
	if (date && date.toString().indexOf('UTC') > -1) {
		console.log("进入")
		dateTime = date.getTime() - calDateTime;
	} else {
		dateTime = date.getTime();
	}

	return dateTime;
}

module.exports = {
	getCurrentDate,
	timestampToFormatInfo,
	getTimestampByStr
}